package com.hongye.backstage.config;

import com.alibaba.fastjson.JSON;
import com.hongye.backstage.dao.HongyeIssueTypeDao;
import com.hongye.backstage.entity.HongyeIssueTypeEntity;
import com.hongye.backstage.service.HongyeIssueTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.List;

/**
 * @author fyd
 * @email 2104371759@qq.com
 * @date 2022/4/20
 * @time 15:54
 */
//@Configuration
public class ApplicationRunnerConfig implements ApplicationRunner {

    @Autowired(required = false)
    private HongyeIssueTypeDao hongyeIssueTypeDao;

    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 项目启动将发布房源类型 以字符串的形式存入Redis
     * @param args
     * @throws Exception
     */
    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<HongyeIssueTypeEntity> typeListAll = hongyeIssueTypeDao.getIssueTypeListAll();
        String jsonString = JSON.toJSONString(typeListAll);
        redisTemplate.opsForValue().set("IssueTypeList",jsonString);
    }
}
